/*
package NiuKe;

import java.util.Scanner;

*/
/**
 * @Description:
 * @Author: Hanzao
 * @Date: 2022/06/13/23:04
 *//*

public class HJ22 {
    public static int hzh(int num) {
        int res = 0;
        while (num != 0) {
            if (num / 3 > 0) {
                res += (num / 3);
                num = num / 3 + num % 3;
            } else if (num == 2) {
                num = 0;
                res += 1;
            } else{
                break;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int i = scanner.nextInt();
            if (i == 0) break;
            System.out.println(hzh(i));
        }
    }
}
*/
